<?php
class M_DbTable_Offer extends Apps_Db_Table_Abstract {
	protected $_name = 'offer';

	const STATUS_ACTIVE 	= 1;
	const STATUS_INACTIVE 	= 0;

	const REFERENCE_TYPE_TOUR 	= 1;
	const REFERENCE_TYPE_HOTEL	= 2;

	public function getListActive() {
		$q = $this->_db
				  ->select()
				  ->from('offer')
				  ->joinLeft('tour', 'offer.reference_type = '. self::REFERENCE_TYPE_TOUR . ' AND tour.id = reference_id', null)
				  ->joinLeft('hotel', 'offer.reference_type = '. self::REFERENCE_TYPE_HOTEL . ' AND hotel.id = reference_id', null)
				  ->where('offer.status = ?', self::STATUS_ACTIVE);
		return $q;
	}

	public function getofferyById($offerId) {
		$q = $this->_db
				  ->select()
				  ->from('offer')
				  ->joinLeft('tour', 'offer.reference_type = '. self::REFERENCE_TYPE_TOUR . ' AND tour.id = reference_id', null)
				  ->joinLeft('hotel', 'offer.reference_type = '. self::REFERENCE_TYPE_HOTEL . ' AND hotel.id = reference_id', null)
				  ->where('offer.status = ?', self::STATUS_ACTIVE)
				  ->where('offer.id = ?', $offerId);
		return $q;
	}
}